package huawei;

/**
 * @author: yfq
 * @date: 2023/3/15 17:47
 * @description:
 */
public class Demo05 {
    public static void main(String[] args) {
        //[7,1,5,3,6,4]
        int[] arr = new int[]{7, 1, 5, 3, 6, 4};

        System.out.println(f(arr));

    }

    public static int f(int[] prices) {
        int minPrice = Integer.MAX_VALUE;
        int maxProfit = 0;

        for (int i = 0; i < prices.length; i++) {
            if (minPrice > prices[i]) {
                minPrice = prices[i];
            } else if (prices[i] - minPrice > maxProfit) {
                maxProfit = prices[i] - minPrice;
            }
        }

        return maxProfit;
    }
}
